package cz.fit.vutbr.pis2012.augeaswh.control.ekonom.orders;

import java.math.BigDecimal;
import java.util.List;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import cz.fit.vutbr.pis2012.augeaswh.managers.OrderedItemsManager;
import cz.fit.vutbr.pis2012.augeaswh.persistence.Order;
import cz.fit.vutbr.pis2012.augeaswh.persistence.OrdersStockType;
import cz.fit.vutbr.pis2012.augeaswh.persistence.StockType;

@ManagedBean
@SessionScoped
public class OrdersAddItemBean {
	@EJB
	private OrderedItemsManager oim;
	private Order order=null;
	private StockType stockType;
	private BigDecimal amount;
	
	public Order getOrder() {
		return order;
	}
	public void setOrder(Order order) {
		this.order = order;
		this.stockType=null;
	}
	public StockType getStockType() {
		return stockType;
	}
	public void setStockType(StockType stockType) {
		this.stockType = stockType;
	}
	
	public BigDecimal getAmount() {
		return amount;
	}
	public void setAmount(BigDecimal amount) {
		this.amount = amount;
	}	
	
	public List<StockType> getNonOrderedStockTypes() {
		return oim.getNotOrderedStockTypes(this.order);
	}
	
	public String submit() {
		if(this.order!=null) {
			OrdersStockType ost=new OrdersStockType();
			ost.setAmmount(this.amount);
			ost.setStockType(this.stockType);
			ost.setOrder(order);
			oim.save(ost);
			this.order=null;
		}
		return "back";
	}		
}
